package com.example.factory.api.dto;

/**
 * @author Lei Tao
 */
public class PageResponse<D> extends Response<D> {

    private long total;

    private long totalPages;

    public PageResponse(int status, String msg) {
        super(status, msg);
    }

    public PageResponse(int status, String msg, D data) {
        super(status, msg, data);
    }


    public static <D> PageResponse<D> success(long total, int totalPages, D data) {
        PageResponse<D> pageResponse = new PageResponse<>(0, "success", data);
        pageResponse.total = total;
        pageResponse.totalPages = totalPages;
        return pageResponse;
    }

    public static <D> PageResponse<D> success(D data) {
        PageResponse<D> pageResponse = new PageResponse<D>(0, "success", data);
        pageResponse.total = 0;
        pageResponse.totalPages = 0;
        return pageResponse;
    }

    public static <D> PageResponse<D> failed(int status, String msg) {
        return new PageResponse<D>(status, msg);
    }

    public long getTotal() {
        return total;
    }

    public void setTotal(long total) {
        this.total = total;
    }

    public long getTotalPages() {
        return totalPages;
    }

    public void setTotalPages(long totalPages) {
        this.totalPages = totalPages;
    }
}
